<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 二维数组转置
    var arr = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'], ['j', 'k', 'l']];
    var res = [];
    for (var i = 0; i < arr[0].length; i++) {
      res[i] = [];
    }
    for (var i = 0; i < arr.length; i++) {
      for (var j = 0; j < arr[i].length; j++) {
        res[j][i] = arr[i][j];
      }
    }
    console.log(res);


    // 采用冒泡排序，从大到小排序，数组是 70,35,67,49,20,59,98,100
    var arr = [70, 35, 67, 49, 20, 59, 98, 100];
    for (var i = 0; i < arr.length - 1; i++) {
      for (var j = 0; j < arr.length - 1 - i; j++) {
        if (arr[j] < arr[j + 1]) {
          var num = arr[j];
          arr[j] = arr[j + 1];
          arr[j + 1] = num;
        }
      }
    }
    document.write(arr);
    document.write('<br>');
    // 输出任意一个二维数组中数据的个数
    var arr = [[5, 6, 2, 9, 7], [5, 8, 6, 1, 7]];
    var num = 0;
    for (var i = 0; i < arr.length; i++) {
      for (var j = 0; j < arr[i].length; j++) {
        num++;
      }
    }
    document.write('二维数组中数据的个数为：' + num);
    // 数组去重
    /*  var arr = [98, 52, 46, 98, 54, 62, 46, 32];
     for (var i = 0; i < arr.length; i++) {
       for (var j = i + 1; j < arr.length; j++) {
         if (arr[i] == arr[j]) {
           delete arr[j];
         }
       }
     }
     console.log(arr); */
    var arr1 = [98, 52, 46, 98, 54, 62, 46, 32];
    var arr2 = [];
    for (var v of arr1) {
      var ha = false;
      for (var w of arr2) {
        if (v == w) {
          ha = true;
        }
      }
      if (!ha) {
        arr2[arr2.length] = v;
      }
    }
    console.log(arr2);
  </script>
</body>

</html>